package reader

import (
	"context"
	"io"
)

const (
	Success byte = 0x10
)

type TagType uint
const (
	TagInfoType    TagType = 0x01
	TagSummaryType TagType = 0x02
	InventoryError TagType = 0x03
)

type Reader struct {
	// 配置
	opts Options

	// 连接
	conn io.ReadWriteCloser
	readBuffer []byte

	readBufferToken int

	State bool

	Ctx context.Context
}

type TagInfo struct {
	FreqAnt byte `json:"-"`
	PC []byte `json:"-"`
	TID []byte `json:"-"`
	TidText string `json:"tid,omitempty"`
	EPC []byte `json:"-"`
	EpcText string `json:"epc"`
	RSSI byte `json:"-"`
}

type TagSummary struct {
	AntID byte
	ReadRate []byte
	TotalRead []byte
}

type InventoryInfo struct {
	TagInfo TagInfo
	TagSummary TagSummary
	PacketType TagType
}

type Callback func(data TagInfo)

type Options struct {

	// 码率
	BaudRate uint

	// 串口
	PortName string

	// 天线列表
	Antennas []uint
}

type SerialHandler interface {

	readPacketHead() int

	readPacketBody(packetSize int) []byte

	// 发送数据参数为数据包body部分. 会自动添加head len check
	writeSerialBody([]byte) int

	// 发送数据
	writeSerial([]byte) int
}

type RFIDHandler interface {

	Open(*Options)

	Close()

	Inventory(Callback)
}